namespace SimpleWebServices.Web
{
    using System;
    using System.Web;
    using Moq;
    using SimpleWebServices;
    using Xunit;

    public sealed class HeaderSuppressionModuleFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<HeaderSuppressionModule>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IHttpModule>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new HeaderSuppressionModule());
        }

        [Fact]
        public void op_Dispose()
        {
            new HeaderSuppressionModule().Dispose();
        }

        [Fact]
        public void op_Init_HttpApplication()
        {
            new HeaderSuppressionModule().Init(new Mock<HttpApplication>().Object);
        }

        [Fact]
        public void op_Init_HttpApplicationNull()
        {
            Assert.Throws<ArgumentNullException>(() => new HeaderSuppressionModule().Init(null as HttpApplication));
        }

        [Fact]
        public void op_OnPreSendRequestHeaders_object_EventArgs()
        {
            try
            {
                var mock = new Mock<HttpContextBase>();
                mock.Setup(x => x.Response.Headers.Remove("Server")).Verifiable();
                mock.Setup(x => x.Response.Headers.Remove("X-AspNetMvc-Version")).Verifiable();
                mock.Setup(x => x.Response.Headers.Remove("X-AspNet-Version")).Verifiable();
                HttpContextFactory.Mock = mock.Object;

                new HeaderSuppressionModule().OnPreSendRequestHeaders(null as object, EventArgs.Empty);

                mock.VerifyAll();
            }
            finally
            {
                HttpContextFactory.Reset();
            }
        }
    }
}